// getter and setter
class Person {
	constructor(private _name: string) {}
	get getName() {
		return this._name + " lee";
	}
	set setName(name: string) {
		const realName = name.split(" ")[0];
		this._name = realName;
	}
}

const person = new Person("dell");
person.getName;
console.log(person.getName);
person.setName = "dylan ccccccc";
console.log(person.getName);

//单例模式
class Demo1 {
	private static instance: Demo;
	private constructor(public name: string) {}

	static getInstance(name: string) {
		if (!this.instance) {
			this.instance = new Demo1(name);
		}
		return this.instance;
	}
}
class Demo {
	private static instance: Demo;
	private constructor(public name: string) {}

	static getInstance() {
		if (!this.instance) {
			this.instance = new Demo("dell lee");
		}
		return this.instance;
	}
}

const demo1 = Demo.getInstance();
const demo2 = Demo.getInstance();
console.log(demo1.name);
console.log(demo2.name);
